package com.weareint.common.advices.utils;

@SuppressWarnings("AlibabaUndefineMagicConstant")
public abstract class MethodTypeUtil {

    /**
     * 按方法名命名规则，判断此方法的操作类型
     *
     * @param methodName 方法名
     * @return com.weareint.commons.advices.utils.MethodTypeUtil.TYPE
     */
    public static TYPE toType(String methodName) {
        if (methodName.startsWith("find") || methodName.startsWith("getBy")) {
            return TYPE.FIND;
        } else if (methodName.startsWith("saveOrUpdate")) {
            return TYPE.SAVE_OR_UPDATE;
        } else if (methodName.startsWith("delete") || methodName.startsWith("remove")) {
            return TYPE.DELETE;
        } else if (methodName.startsWith("save")) {
            return TYPE.SAVE;
        } else if (methodName.startsWith("update")) {
            return TYPE.UPDATE;
        } else {
            return TYPE.OTHER;
        }
    }

    public enum TYPE {
        FIND("find"),
        SAVE("save"),
        UPDATE("update"),
        DELETE("delete"),
        SAVE_OR_UPDATE("saveOrUpdate"),
        OTHER("other");

        private String val;

        TYPE(String val) {
            this.val = val;
        }

        public String getVal() {
            return val;
        }
    }
}
